home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CU Amiga Super CD-ROM 11
/
CU Amiga Magazine's Super CD-ROM 11 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-06].iso
/
cucd
/
programming
/
oberonv4
/
source
/
system
/
keycmds.mod
(
.txt
)
< prev
next >
Wrap
Oberon Text
|
1994-06-16
|
6KB
|
135 lines
Syntax10.Scn.Fnt
Syntax10i.Scn.Fnt
Syntax10b.Scn.Fnt
MODULE KeyCmds; (* CAS 19-Jun-91 *) (*sample extensions of EdiTKeys / TBoxKeys / WriteKeys*)
IMPORT
Oberon, Display, Fonts, Viewers, MenuViewers, Texts, TextFrames;
CONST
cpm = 3; (*characters per month name*)
mnam: ARRAY 12*cpm + 1 OF CHAR;
lastTime: LONGINT;
W: Texts.Writer;
B: Texts.Buffer;
PROCEDURE Ch(ch: CHAR);
BEGIN Texts.Write(W, ch)
END Ch;
PROCEDURE Int(x: LONGINT);
BEGIN Texts.WriteInt(W, x, 0)
END Int;
PROCEDURE Int2(x: LONGINT);
BEGIN
IF x > 10 THEN Ch(CHR(x DIV 10 + 30H)) ELSE Ch("0") END;
Ch(CHR(x MOD 10 + 30H))
END Int2;
PROCEDURE Month(m: LONGINT);
VAR i, j: LONGINT;
BEGIN j := m * cpm; i := j - cpm; REPEAT Ch(mnam[i]); INC(i) UNTIL i = j
END Month;
PROCEDURE InsertAtCaret(buf: Texts.Buffer);
VAR msg: Oberon.CopyOverMsg;
BEGIN msg.text := TextFrames.Text(""); msg.beg := 0; msg.end := buf.len;
Texts.Insert(msg.text, 0, buf); Oberon.FocusViewer.handle(Oberon.FocusViewer, msg)
END InsertAtCaret;
PROCEDURE MarkedText(): Texts.Text;
VAR v: Viewers.Viewer;
BEGIN v := Oberon.MarkedViewer();
IF (v IS MenuViewers.Viewer) & (v.dsc.next IS TextFrames.Frame) THEN
RETURN v.dsc.next(TextFrames.Frame).text
ELSE RETURN NIL
END
END MarkedText;
PROCEDURE DateStamp*; (**EdiTKeys, TBoxKeys, and WriteKeys**)
VAR S: Texts.Scanner; date, time: LONGINT;
BEGIN Oberon.GetClock(time, date); Texts.OpenScanner(S, Oberon.Par.text, Oberon.Par.pos); Texts.Scan(S);
IF S.class = Texts.Name THEN Texts.SetFont(W, Fonts.This(S.s)) ELSE Texts.SetFont(W, Fonts.Default) END;
Int(date MOD 20H); Ch(" "); Month( (date DIV 20H) MOD 10H ); Ch(" "); Int2( (date DIV 200H) MOD 100 );
InsertAtCaret(W.buf)
END DateStamp;
PROCEDURE DateStamp1*; (**EdiTKeys, TBoxKeys, and WriteKeys**)
VAR S: Texts.Scanner; date, time: LONGINT;
BEGIN Oberon.GetClock(time, date); Texts.OpenScanner(S, Oberon.Par.text, Oberon.Par.pos); Texts.Scan(S);
IF S.class = Texts.Name THEN Texts.SetFont(W, Fonts.This(S.s)) ELSE Texts.SetFont(W, Fonts.Default) END;
Int(date MOD 20H); Ch("-"); Month( (date DIV 20H) MOD 10H ); Ch("-"); Int2( (date DIV 200H) MOD 100 );
InsertAtCaret(W.buf)
END DateStamp1;
PROCEDURE ChangeFont*; (**EdiTKeys, TBoxKeys, and WriteKeys**)
VAR S: Texts.Scanner; text: Texts.Text;
BEGIN Texts.OpenScanner(S, Oberon.Par.text, Oberon.Par.pos); Texts.Scan(S);
IF S.class = Texts.Name THEN text := MarkedText();
IF text # NIL THEN Texts.ChangeLooks(text, 0, text.len, {0}, Fonts.This(S.s), 0, 0) END
END
END ChangeFont;
PROCEDURE ChangeColor*; (**EdiTKeys, TBoxKeys, and WriteKeys**)
VAR S: Texts.Scanner; text: Texts.Text;
BEGIN Texts.OpenScanner(S, Oberon.Par.text, Oberon.Par.pos); Texts.Scan(S);
IF (S.class = Texts.Int) & (0 <= S.i) & (S.i < 16) THEN text := MarkedText();
IF text # NIL THEN Texts.ChangeLooks(text, 0, text.len, {1}, NIL, SHORT(SHORT(S.i)), 0) END
END
END ChangeColor;
PROCEDURE ChangeOffset*; (**EdiTKeys, TBoxKeys, and WriteKeys**)
VAR S: Texts.Scanner; text: Texts.Text;
BEGIN Texts.OpenScanner(S, Oberon.Par.text, Oberon.Par.pos); Texts.Scan(S);
IF (S.class = Texts.Int) & (-128 <= S.i) & (S.i < 128) THEN text := MarkedText();
IF text # NIL THEN Texts.ChangeLooks(text, 0, text.len, {2}, NIL, 0, SHORT(SHORT(S.i))) END
END
END ChangeOffset;
PROCEDURE Include*; (**EdiTKeys, TBoxKeys, and WriteKeys**)
VAR S: Texts.Scanner; buf: Texts.Buffer; text: Texts.Text; beg, end: LONGINT;
BEGIN NEW(buf); Texts.OpenBuf(buf); Texts.OpenScanner(S, Oberon.Par.text, Oberon.Par.pos); Texts.Scan(S);
IF S.class = Texts.Name THEN text := TextFrames.Text(S.s); Texts.Scan(S); beg := 0;
IF S.class = Texts.Int THEN end := S.i; Texts.Scan(S);
IF S.class = Texts.Int THEN beg := end; end := S.i END
ELSE end := text.len
END;
IF (0 <= beg) & (beg < end) & (end <= text.len) THEN Texts.Save(text, beg, end, buf); InsertAtCaret(buf) END
END
END Include;
PROCEDURE MarkFocus*;
VAR v: Viewers.Viewer; x, y: INTEGER;
BEGIN v := Oberon.FocusViewer; x := v.X + v.W DIV 2; y := v.Y + v.H DIV 2;
Oberon.DrawCursor(Oberon.Pointer, Oberon.Star, x, y)
END MarkFocus;
PROCEDURE Save*;
VAR text: Texts.Text; beg, end, time: LONGINT;
BEGIN Oberon.GetSelection(text, beg, end, time);
IF time >= lastTime THEN Texts.OpenBuf(B); Texts.Save(text, beg, end, B) END
END Save;
PROCEDURE Paste*;
VAR buf: Texts.Buffer;
BEGIN NEW(buf); Texts.OpenBuf(buf); Texts.Copy(B, buf); InsertAtCaret(buf)
END Paste;
PROCEDURE GetRange (VAR text: Texts.Text; VAR org, end: LONGINT);
VAR s: Texts.Scanner; v: Viewers.Viewer; f: TextFrames.Frame;
BEGIN text := NIL; org := 0; end := 0;
Texts.OpenScanner(s, Oberon.Par.text, Oberon.Par.pos); Texts.Scan(s);
IF s.class # Texts.Int THEN s.i := 1 END;
IF Oberon.FocusViewer IS MenuViewers.Viewer THEN v := Oberon.FocusViewer(MenuViewers.Viewer);
IF v.dsc.next IS TextFrames.Frame THEN f := v.dsc.next(TextFrames.Frame);
IF f.hasCar THEN text := f.text; end := f.carloc.pos - s.i END
END
END
END GetRange;
PROCEDURE Bold*;
VAR r: Texts.Reader; text: Texts.Text; org, beg, end: LONGINT; ch: CHAR; name: ARRAY 32 OF CHAR;
BEGIN GetRange(text, org, end); beg := end;
LOOP
IF beg <= org THEN EXIT END;
Texts.OpenReader(r, text, beg-1); Texts.Read(r, ch);
IF ~( (ch = ".") OR ("0" <= ch) & (ch <= "9") OR ("A" <= CAP(ch)) & (CAP(ch) <= "Z") ) THEN EXIT END;
DEC(beg)
END;
IF beg < end THEN
Texts.OpenReader(r, text, end); Texts.Read(r, ch);
name := "Syntax10b.Scn.Fnt";
IF r.fnt # Fonts.This("Syntax10.Scn.Fnt") THEN name := "Syntax12b.Scn.Fnt" END;
Texts.ChangeLooks(text, beg, end, {0}, Fonts.This(name), 0, 0)
END
END Bold;
PROCEDURE ToBottom*;
VAR f: TextFrames.Frame;
BEGIN f := Oberon.FocusViewer.dsc.next(TextFrames.Frame); TextFrames.Show(f, f.text.len)
END ToBottom;
BEGIN Texts.OpenWriter(W); NEW(B); Texts.OpenBuf(B);
mnam := "JanFebMarAprMayJunJulAugSepOctNovDec"; lastTime := 0
END KeyCmds.